<template>
  <div>
    <div class="head">
        <h3>最近播放<span>共{{historyList.length}}首</span></h3>
        <div :class="historyList.length>0 ? 'clear' : 'none'" @click="clearHistory()"><span>清空列表</span></div>
    </div>
    <div class="btn" v-show="historyList.length>0">
        <div class="playAll">
          <i class="iconfont icon-bofang"></i>
          <span>播放全部</span>
          <i class="iconfont icon-zengjia"></i>
        </div>
    </div>
    <div class="songList" v-show="historyList.length>0">
      <song-list-base :playList="historyList"></song-list-base>
    </div>
    <div class="tip" v-show="historyList.length==0">你还没有听任何歌哦！快去听歌吧</div>
  </div>
</template>

<script>
import SongListBase from '@/components/SongListBase.vue';
export default {
  components: { SongListBase },
    name:'History',
    data() {
      return {
      }
    },
    methods:{
      // 清空播放历史
      clearHistory(){
        this.$store.commit('play/clearPlayHistory');
        localStorage.removeItem('historySheet');
      }
    },
    computed:{
      historyList(){
        return this.$store.state.play.playHistory;
      }
    }
}
</script>

<style lang="less" scoped>
.head{
  width: 95%;
  margin: 10px auto 10px;
  height: 30px;
  display: flex;
  justify-content: space-between;
  h3{
    margin: 0;
    line-height: 30px;
    color: #555;
    span{
      padding-left: 10px;
      font-weight: normal;
      color: #b0b0b0;
      font-size: 13px;
    }
  }
  .clear{
    line-height: 30px;
    font-size: 14px;
    color: rgb(59, 144, 204);
    span{
      cursor: pointer;
    }
    span:hover{
      color: rgb(41, 103, 147);
    }
  }
  .none{
    line-height: 30px;
    font-size: 14px;
    color: #aaa;
    span{
      cursor:default;
    }
  }
}
.btn {
  width: 95%;
  margin: 15px auto 20px;
  display: flex;
  font-weight: lighter;
  font-size: 15px;
  .playAll {
    margin-right: 10px;
    height: 32px;
    background-color: #ff7a9e;
    color: white;
    line-height: 32px;
    padding: 0 15px;
    border-radius: 16px;
    cursor: pointer;
    i {
      font-size: 14px;
    }
    span {
      padding: 0 6px;
    }
    .icon-zengjia {
      padding-left: 5px;
      border-left: 1px solid rgba(255, 255, 255, 0.2);
    }
  }
  .playAll:hover{
     background-color: rgb(222, 104, 138);
  }
}
.tip{
  margin: 200px auto;
  font-size: 14px;
  color: #b0b0b0;
  text-align: center;
}
</style>